// index.js
import {request, requestWrap} from "../../request/index.js"
import {checkLogin} from '../../request/index.js'
Page({
    data: {
        banner: [],
        listData: [],
        indicatorDots: true,
        vertical: false,
        autoplay: false,
        interval: 2000,
        duration: 500,
        student: ''
    },
    userInfo: '',
    onLoad () {
    },
    onShow () {
        this.userInfo = getApp().getUserInfo()
        this.setData({
            student: wx.getStorageSync('student')
        })
        this.getBanner()
    },
    openWin (e) {
        let url = e.currentTarget.dataset.url
        if (url != '/pages/changestudent/changestudent' && !this.data.student) {
            url = ''
        }
        if (this.userInfo && this.userInfo.is_complete == 1) {
            if (url == '/pages/changestudent/changestudent') {
                wx.navigateTo({
                    url,
                    events:{
                        onchange: (data) => { //从其他页面返回的参数
                            this.setData({
                                student: wx.getStorageSync('student')
                            })
                        }
                      }
                })
            } else {
                if (!url) {
                    wx.showToast({
                        title: '请选择学生',
                        icon: 'none'
                    })
                } else {
                    wx.navigateTo({
                        url
                    })
                }
            }
        } else {
            checkLogin(url, 'index').then(res => {
                console.log(res)
                if (res) {
                    this.userInfo = getApp().getUserInfo()
                }
            })
        }
    },
    async getBanner () {
        let res = requestWrap(await request({
            url:"api/home/slides/1",
            method:'GET',
            data: {}
        }))
        if (res && res.code == 1) {
            this.setData({
                banner: res.data['0'].items
            })
        }
    }
})
